package com.huaxin.hxcloud.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;

import com.huaxin.common.BaseActivity;
import com.huaxin.common.Constants;
import com.huaxin.common.view.MyFragmentTabHost;
import com.huaxin.hxcloud.R;
import com.huaxin.hxcloud.fragment.MyReportListFragment;
import com.huaxin.hxcloud.fragment.ReportFragment;

import butterknife.BindView;


/**
 * Created by Administrator on 2016/9/6.
 */
public class ReportActivity extends BaseActivity implements TabHost.OnTabChangeListener {
    public static final int IMAGE_ITEM_ADD = -1;
    public static final int TYPE_REPORT = 0x00;
    public static final int TYPE_RECORD = 0x01 ;
    @BindView(R.id.vRealTabContent)
    FrameLayout vRealTabContent;
    @BindView(R.id.vTabHost)
    MyFragmentTabHost vTabHost;
    private int _type;


    public static void start(Context context,int type){
        Intent intent = new Intent(context,ReportActivity.class);
        intent.putExtra(Constants.IK_TYPE,type);
        context.startActivity(intent);
    }

    @Override
    protected void getBundleExtras(Bundle extras) {
        super.getBundleExtras(extras);
        _type = extras.getInt(Constants.IK_TYPE,TYPE_REPORT);
    }

    protected int getContentViewId() {
        return R.layout.activity_report_or_attendance;
    }


    @Override
    public void initView() {

        vTabHost.setup(this, getSupportFragmentManager(), R.id.vRealTabContent);
        vTabHost.getTabWidget().setDividerDrawable(null);
        initTabs();
        vTabHost.setCurrentTab(_type);
        vTabHost.setOnTabChangedListener(this);


    }

    private void initTabs() {

        TabHost.TabSpec tab = vTabHost.newTabSpec("申报");
        View indicator = View.inflate(this, R.layout.tab_indicator, null);
        TextView title = (TextView) indicator.findViewById(R.id.tab_title);
        ImageView icon = (ImageView) indicator.findViewById(R.id.iv_icon);
        icon.setImageResource(R.drawable.tab_icon_report);
        title.setText("申报");
        tab.setIndicator(indicator);
        vTabHost.addTab(tab, ReportFragment.class, null);

        TabHost.TabSpec tab2 = vTabHost.newTabSpec("我的申报");
        View indicator2 = View.inflate(this, R.layout.tab_indicator, null);
        TextView title2 = (TextView) indicator2.findViewById(R.id.tab_title);
        ImageView icon2 = (ImageView) indicator2.findViewById(R.id.iv_icon);
        icon2.setImageResource(R.drawable.tab_icon_my_report);
        title2.setText("我的申报");
        tab2.setIndicator(indicator2);
        vTabHost.addTab(tab2, MyReportListFragment.class, null);


    }

    @Override
    public void onTabChanged(String tabId) {
        final int size = vTabHost.getTabWidget().getTabCount();
        for (int i = 0; i < size; i++) {
            View v = vTabHost.getTabWidget().getChildAt(i);
            if (i == vTabHost.getCurrentTab()) {
                v.setSelected(true);
            } else {
                v.setSelected(false);
            }
        }

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
    }
}


